public class BlockingQueue {
    public int[] elem;
    volatile public int size;
    volatile public int head;
    volatile  public int last;
    public BlockingQueue() {
        elem = new int[10000];
        size = 0;
    }

    synchronized public int take() throws InterruptedException {
        while(size == 0) {
            this.wait();
        }
        int val = elem[head];
        head++;
        if(head == elem.length) {
            head = 0;
        }
        size--;
        this.notify();
        return val;
    }
    synchronized public void put(int val) throws InterruptedException {
        while(size == elem.length) {
            this.wait();
        }
        elem[last] = val;
        last++;
        if(last == elem.length) {
            last = 0;
        }
        size++;
        this.notify();
    }
}
